<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
const posts = [
    { title: 'I Love JavaScript', author: '计涛', id: 1 },
    { title: 'CSS', author: '涛哥', id: 2 },
    { title: 'Dev tools webpack', author:'CEO' }
];

const authors = [
    {name:'计涛',hometown:'九江',bio:'面向字节跳动编程'}
]

function getPostById(id) {
    // // id 找到文章
    // const post = post.find(post => post.id === id);
    // const { author } = post;
    // // const authors = authors.find(author =>author.name == author)
    // console.log(authors.find(item => item.name == author));
    // return post
    return new Promise((resolve,reject)=>{
        // resolve()
        setTimeout(()=>{
            const post = posts.find(post => post.id ==id)
            // console.log(post);
            if(post) {
                resolve();
            }else{
                let err = new Error('没有数据')
                reject(err)
            }
        },200)
    })
}
getPostById(10)
    .then((data)=>{
        console.log(data,'////////////')
    })
    .catch((err)=>{
        console.log(err.message);
    })
// pst.push({
//     title:'Dev tools webpack',
//     author:'CEO'
// })
// localStorage.setItem('posts', JSON.stringify(posts))
</script>
</body>
</html>